package com.example.testing.ipcdemo;

import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;

import java.util.List;

/**
 * Created by tangjiangxu on 9/4/17.
 */

public class MyDeathRecipient {
    private com.example.testing.ipcdemo.IBookManager mService;

    IBookManager.Stub mBookManager = new IBookManager.Stub() {
        @Override
        public List<Book> getBookList() throws RemoteException {
            return null;
        }

        @Override
        public void addBook(Book book) throws RemoteException {

        }

        @Override
        public void registerLisenter(IOnNewBookArrivedListener listener) throws RemoteException {

        }

        @Override
        public void unRegisterLisenter(IOnNewBookArrivedListener listener) throws RemoteException {

        }
    };

    private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient(){

        @Override
        public void binderDied() {
            mBookManager.asBinder().unlinkToDeath(mDeathRecipient, 0);
            mBookManager = null;
            //这里重新绑定远程Service
        }
    };

    private void bindSuccess(Binder binder) {
        mService = IBookManager.Stub.asInterface(binder);
        binder.linkToDeath(mDeathRecipient, 0);
    }
}
